package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.entity.Category;
import com.itheima.mapper.CategoryMapper;
import com.itheima.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
*@author: lzl
*@description: 菜品、套餐分类管理-业务实现类
*@date:Acer
*/
@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;


    /**
     * 获取菜品分类列表数据
>>>>>>> Stashed changes
     *
     * @param type
     * @return
     */

    @Override
    public List<Category> findAll(Integer type) {
        LambdaQueryWrapper<Category> wrapper = new LambdaQueryWrapper<>();
        //如果类型不为空 new Lam然后eq查询
        if (type != null) {
            wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(Category::getType, type);
        }
        //根据sort字段升序降序
        wrapper.orderByAsc(Category::getSort);
        wrapper.orderByDesc(Category::getUpdateTime);
        List<Category> categoryList = categoryMapper.selectList(wrapper);
        return categoryList;
    }


}
